document.querySelector(".fanhui").onclick = function () {
    location.href = "./index.html"
}

function getname(key) {
    // 转url地址
    let strData = location.href.split('?')[1];
    let arrData = strData.split('=')
    // console.log(arrData[1]);
    return decodeURI(arrData[1])
}


function getGoodlist() {
    // 假设getname函数已经正确实现了获取URL参数的功能
    const keyword = getname("name");
    // console.log(keyword);

    // 如果keyword存在，构建请求数据，否则直接返回
    ajaxUsePromise02({
        url: `http://localhost:3000/books`,
        method: "get",
        data: `keyword=${encodeURIComponent(keyword)}`
    }).then(res => {
        for (let i = 0; i < res.length; i++) {
            if (keyword == res[i].id) {
                // console.log(res[i]);
                paylist(res[i])
            }
        }
    });
}

function getcoolietime() {
    let paytime = document.querySelector(".payInformationtime")
    let time = getCookie("paytime")
    paytime.innerHTML = time
}


// 渲染数据
function paylist(data) {
    console.log(data);
    let paytitpic = document.querySelector(".paytit-pic")
    let payInformationpic = document.querySelector(".payInformationpic")

    paytitpic.innerHTML = `￥${data.price - 5}`
    payInformationpic.innerHTML = `￥${data.price}`


    document.getElementById("View-btn").onclick = function () {
        // console.log(res[i].id);
        location.href = `./view.html?category=${data.id}`
    }
}

window.onload = function () {
    getGoodlist();
    getcoolietime();
}